<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ForumService
 *
 * @author admin
 */
class Service_ForumService {
    public function __construct()
    {

    }
    public function getForumTopic($id)
    {
        $forumMapper = new Application_Model_ForumTopicMapper();
        $forum = $forumMapper->fetchById($id);
        $forumVO = $this->_toForumTopicVO($forum);
        return $forumVO;
    }
    public function getForumReply($id)
    {
        $forumMapper = new Application_Model_ForumReplyMapper();
        $forum = $forumMapper->fetchById($id);
        $forumVO = $this->_toForumTopicVO($forum);
        return $forumVO;
    }
    /**
     * @return array
     */
    public function getForumTopics()
    {   
        $forumMapper = new Application_Model_ForumTopicMapper();
        $forums = $forumMapper->fetchAll();

        $forumVOs = $this->_toForumTopicVOs($forums);

        return $forumVOs;
    }
    
    public function getForumReplies()
    {   
        $forumMapper = new Application_Model_ForumReplyMapper();
        $forums = $forumMapper->fetchAll();

        $forumVOs = $this->_toForumReplyVOs($forums);

        return $forumVOs;
    }
    /**
     * @return array
     */
    public function getForumsTopicList()
    {
        return $this->getForumTopics();
    }
    
    public function getForumsRepliesList()
    {
        return $this->getForumReplies();
    }

    /**
     * @param Application_Model_ForumTopic $forum
     * @return VO_Forum
     */
    private function _toForumTopicVO(Application_Model_ForumTopicMapper $forum)
    {
        $forumVO = new VO_ForumTopic();
        $forumVO->id                = $forum->Id;
        $forumVO->topicprojectid    = $forum->TopicProjectId;
        $forumVO->title             = $forum->Title;
        $forumVO->creationdate      = $forum->Creationdate;
        $forumVO->creator           = $forum->Creator;
        $forumVO->deleted           = $forum->Deleted;
        $forumVO->modifieddate      = $forum->Modifieddate;

        return $forumVO;
    }
    
    private function _toForumReplyVO(Application_Model_ForumReplyMapper $forum)
    {
        $forumVO = new VO_ForumReply();
        $forumVO->id            = $forum->Id;
        $forumVO->topicid       = $forum->TopicId;
        $forumVO->creator       = $forum->Creator;
        $forumVO->message       = $forum->Message;
        $forumVO->creationdate  = $forum->Creationdate;
        $forumVO->modifieddate  = $forum->Modifieddate;
        $forumVO->deleted       = $forum->Deleted;

        return $forumVO;
    }

    /**
     * @param array $forum
     * @return array
     */
    private function _toForumTopicVOs($forums = array())
    {
        $forumVOs = array();
        foreach ($forums as $forum) {
            $forumVOs[] = $this->_toForumTopicVO($forum);
        }

        return $forumVOs;
    }
    
    private function _toForumReplyVOs($forums = array())
    {
        $forumVOs = array();
        foreach ($forums as $forum) {
            $forumVOs[] = $this->_toForumReplyVO($forum);
        }

        return $forumVOs;
    }
    
    public function logOut()
    {
        Zend_Auth::getInstance()->clearIdentity();
    }
}

?>
